﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using Rj.PersonnelVerification.Server.DataBaseContext;
using Rj.PersonnelVerification.Server.Servers;
using Rj.PersonnelVerification.Shared.Models;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;

namespace Rj.PersonnelVerification.Server.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class AuthController : ControllerBase
    {
        private HisDbContext HisDbContext;
        private IAuthService AuthService;

        public AuthController(HisDbContext hisDbContext
            , IAuthService authService)
        {
            this.HisDbContext = hisDbContext;
            this.AuthService = authService;
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost("login")]
        public IActionResult Login([FromBody] LoginModel model)
        {
            if(AuthService.Login(model, out string token))
            {
                return Ok(token);
            }else
                return Unauthorized(token);
        }
        
    }
}
